#include <stdio.h>
#include <stdlib.h>
#include "estructuras.h"
extern int descomprimir_buffer(unsigned char *src_buf, unsigned int long_codificacion, unsigned char *dst_buf, unsigned int dst_size, codigo_t *tabla_codigo);

extern unsigned int* generar_tabla_apariciones(unsigned char *buf, unsigned int size);
extern codigo_t* generar_tabla_codigos(unsigned int *tabla_apariciones);
extern int calcular_longitud_codificacion(unsigned int *tabla_apariciones, codigo_t *tabla_codigo);
extern int generar_codificacion(unsigned char *src_buf, unsigned int src_size, unsigned char *dst_buf, unsigned int dst_size, codigo_t *tabla_codigos);
int comprimir_buffer(unsigned char *scr_buf, unsigned int scr_size, unsigned char **dst_buf, unsigned int *dst_size, codigo_t **tabla_codigos, unsigned int *long_codificacion);

// Este test dejo de funcionar cuando corregimos los free. No pudimos identificar todavia donde fallaba.

int main(){
	char ruta[37]= "/home/pablo/pepe.oc2";
	FILE *fp = fopen(ruta,"r");
	unsigned int size;
	fseek(fp,0,SEEK_END);
	size = ftell(fp);
	rewind(fp);
	
	unsigned char *src_buf = (unsigned char *)malloc(size);
	
	fread(src_buf,size,1,fp);
	
	codigo_t *tabla_codigos;
	tabla_codigos = NULL;
	
	cargar_tabla_codigo_desde_buffer(src_buf, size, &tabla_codigos);
	
	int long_codif = 12;
	
	unsigned char *dst_buf;
	dst_buf = NULL;
	unsigned int dst_size;
	
	int res = descomprimir_buffer(src_buf, long_codif, dst_buf, dst_size, tabla_codigos);
	
	printf("El resultado de descomprimir buffer %d", res);
}
